import { parse } from 'url';
import { TableListItem, TableListParams } from './data.d';

function getContractList(
  req: { url: any },
  res: {
    json: (
      arg0: {
        body: {
          list: TableListItem[];
          count: number,
        }
      },
    ) => void;
  },
  u: any,
) {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== '[object String]') {
    // eslint-disable-next-line prefer-destructuring
    url = req.url;
  }

  const params = (parse(url, true).query as unknown) as TableListParams;

  const dataSource: TableListItem[] = [];

  for (let i = (params.currentPage - 1) * 10; i < 10 * params.currentPage; i++) {
    dataSource.push({
      id: i + 1,
      fcs_id: 100,
      posthouse_id: 50,
      status: 1,
      status_desc: '生效',
      contract_num: 'BJ-PH-SQ-C-2019-00010',
      start_day: '2019-7-7——2019-8-8',
      create_user: '小新',
      create_time: '2019-06-26 17:33:25',
      fcs_name: `龙门客栈${i + 1}`,
    });
  }

  const result = {
    code: 0,
    body: {
      list: dataSource,
      count: 30,
    },
  };

  return res.json(result);
}

export default {
  'GET /contract/list': getContractList,
};
